/*
 *   Copyright 2022. Huawei Technologies Co., Ltd. All rights reserved.
 *
 *      Licensed under the Apache License, Version 2.0 (the "License");
 *      you may not use this file except in compliance with the License.
 *      You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *      Unless required by applicable law or agreed to in writing, software
 *      distributed under the License is distributed on an "AS IS" BASIS,
 *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *      See the License for the specific language governing permissions and
 *      limitations under the License.
 */

package com.huawei.hms.videoeditor.ui.common.database.bean;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import com.huawei.hms.videoeditor.sdk.util.KeepOriginal;
import com.huawei.hms.videoeditor.ui.common.database.dao.DaoSession;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.internal.DaoConfig;

/**
 * DAO for table "CLOUD_MATERIALS_BEAN". THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
 *
 * @since 2020-10-14
 */
@KeepOriginal
public class CloudMaterialsBeanDao extends AbstractDao<CloudMaterialDaoBean, String> {

    public static final String TABLENAME = "CLOUD_MATERIALS_BEAN";

    /**
     * Properties of entity CloudMaterialDaoBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    @KeepOriginal
    public static class Properties {
        public final static Property ID = new Property(0, String.class, "id", true, "ID");

        public final static Property PREVIEW_URL = new Property(1, String.class, "previewUrl", false, "PREVIEW_URL");

        public final static Property NAME = new Property(2, String.class, "name", false, "NAME");

        public final static Property LOCAL_PATH = new Property(3, String.class, "localPath", false, "LOCAL_PATH");

        public final static Property DURATION = new Property(4, Long.class, "duration", false, "DURATION");

        public final static Property TYPE = new Property(5, int.class, "type", false, "TYPE");

        public final static Property CATEGORY_NAME =
            new Property(6, String.class, "categoryName", false, "CATEGORY_NAME");

        public final static Property LOCAL_DRAWABLE_ID =
            new Property(7, int.class, "localDrawableId", false, "LOCAL_DRAWABLE_ID");

    }

    public CloudMaterialsBeanDao(DaoConfig config) {
        super(config);
    }

    public CloudMaterialsBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /**
     * Creates the underlying database table.
     *
     * @param db Database
     * @param ifNotExists ifNotExists
     */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists ? "IF NOT EXISTS " : "";
        db.execSQL("CREATE TABLE " + constraint + "\"CLOUD_MATERIALS_BEAN\" (" + //
            "\"ID\" TEXT PRIMARY KEY NOT NULL ," + // 0: id
            "\"PREVIEW_URL\" TEXT," + // 1: previewUrl
            "\"NAME\" TEXT," + // 2: name
            "\"LOCAL_PATH\" TEXT," + // 3: localPath
            "\"DURATION\" INTEGER," + // 4: duration
            "\"TYPE\" INTEGER NOT NULL," + // 5: type
            "\"CATEGORY_NAME\" TEXT," + // 6: categoryName
            "\"LOCAL_DRAWABLE_ID\" INTEGER NOT NULL);"); // 7: localDrawableId
    }

    /**
     * Drops the underlying database table.
     *
     * @param db Database
     * @param ifExists ifExists
     */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"CLOUD_MATERIALS_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, CloudMaterialDaoBean entity) {
        stmt.clearBindings();

        String id = entity.getId();
        if (id != null) {
            stmt.bindString(1, id);
        }

        String previewUrl = entity.getPreviewUrl();
        if (previewUrl != null) {
            stmt.bindString(2, previewUrl);
        }

        String name = entity.getName();
        if (name != null) {
            stmt.bindString(3, name);
        }

        String localPath = entity.getLocalPath();
        if (localPath != null) {
            stmt.bindString(4, localPath);
        }

        Long duration = entity.getDuration();
        if (duration != null) {
            stmt.bindLong(5, duration);
        }

        int type = entity.getType();
        stmt.bindLong(6, type);

        String categoryName = entity.getCategoryName();
        if (categoryName != null) {
            stmt.bindString(7, categoryName);
        }

        int localDrawableId = entity.getLocalDrawableId();
        stmt.bindLong(8, localDrawableId);
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, CloudMaterialDaoBean entity) {
        stmt.clearBindings();

        String id = entity.getId();
        if (id != null) {
            stmt.bindString(1, id);
        }

        String previewUrl = entity.getPreviewUrl();
        if (previewUrl != null) {
            stmt.bindString(2, previewUrl);
        }

        String name = entity.getName();
        if (name != null) {
            stmt.bindString(3, name);
        }

        String localPath = entity.getLocalPath();
        if (localPath != null) {
            stmt.bindString(4, localPath);
        }

        Long duration = entity.getDuration();
        if (duration != null) {
            stmt.bindLong(5, duration);
        }

        int type = entity.getType();
        stmt.bindLong(6, type);

        String categoryName = entity.getCategoryName();
        if (categoryName != null) {
            stmt.bindString(7, categoryName);
        }

        int localDrawableId = entity.getLocalDrawableId();
        stmt.bindLong(8, localDrawableId);
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
    }

    @Override
    public CloudMaterialDaoBean readEntity(Cursor cursor, int offset) {
        CloudMaterialDaoBean entity = new CloudMaterialDaoBean( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // previewUrl
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // name
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // localPath
            cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4), // duration
            cursor.getInt(offset + 5), // type
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // categoryName
            cursor.getInt(offset + 7) // localDrawableId
        );
        return entity;
    }

    @Override
    public void readEntity(Cursor cursor, CloudMaterialDaoBean entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setPreviewUrl(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setLocalPath(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setDuration(cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4));
        entity.setType(cursor.getInt(offset + 5));
        entity.setCategoryName(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setLocalDrawableId(cursor.getInt(offset + 7));
    }

    @Override
    protected final String updateKeyAfterInsert(CloudMaterialDaoBean entity, long rowId) {
        return entity.getId();
    }

    @Override
    public String getKey(CloudMaterialDaoBean entity) {
        if (entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(CloudMaterialDaoBean entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }

}
